package com.pybox.api;

import com.pybox.service.TMenuService;
import com.pybox.dto.TMenuDto;

import com.pybox.dto.Result;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.*;

/**
* 描述：TMenu Api
* @author wuyingkai
* @date 2018-09-15
*/

@Slf4j
@RequestMapping("/TMenu")
@Api(tags = "TMenu管理接口", description = "TMenu管理接口")
@RestController
@ApiIgnore
public class TMenuApi {

    @Autowired
    private TMenuService service;

    @ApiOperation(value = "创建TMenu", notes = "创建TMenu")
    @RequestMapping(value = "/create", method = RequestMethod.POST)
    public Result<Boolean> save(@RequestBody TMenuDto dto) {
        service.create(dto);
        return Result.ok(true);
    }

    @ApiOperation(value = "删除TMenu", notes = "删除TMenu")
    @RequestMapping(value = "/delete/{id}", method = RequestMethod.DELETE)
    @ApiImplicitParam(name = "id", value = "TMenu id", dataType = "String", paramType = "path")
    public Result<Boolean> delete(@PathVariable("id") Integer id) {
        service.delete(id);
        return Result.ok(true);
    }

    @ApiOperation(value = "更新TMenu", notes = "更新TMenu")
    @RequestMapping(value = "/update/{id}", method = RequestMethod.PUT)
    @ApiImplicitParam(name = "id", value = "TMenu id", dataType = "String", paramType = "path")
    public Result<Boolean> update(@PathVariable("id") Integer id, @RequestBody TMenuDto dto) {
        service.update(id, dto);
        return Result.ok(true);
    }

    @ApiOperation(value = "查询TMenu", notes = "查询TMenu")
    @RequestMapping(value = "/detail/{id}", method = RequestMethod.GET)
    @ApiImplicitParam(name = "id", value = "TMenu id", dataType = "String", paramType = "path")
    public Result<TMenuDto> detail(@PathVariable("id") Integer id) {

        return Result.ok(service.detail(id));
    }

    @ApiOperation(value = "分页查询TMenu", notes = "分页查询TMenu")
    @RequestMapping(value = "/search", method = RequestMethod.GET)
    @ApiImplicitParams({
           @ApiImplicitParam(name = "menuId", value = "menuId", dataType = "string", paramType = "query"),
           @ApiImplicitParam(name = "menuName", value = "menuName", dataType = "string", paramType = "query"),
           @ApiImplicitParam(name = "parentId", value = "parentId", dataType = "string", paramType = "query"),
           @ApiImplicitParam(name = "orderNum", value = "orderNum", dataType = "string", paramType = "query"),
           @ApiImplicitParam(name = "url", value = "url", dataType = "string", paramType = "query"),
           @ApiImplicitParam(name = "menuType", value = "menuType", dataType = "string", paramType = "query"),
           @ApiImplicitParam(name = "visible", value = "visible", dataType = "string", paramType = "query"),
           @ApiImplicitParam(name = "perms", value = "perms", dataType = "string", paramType = "query"),
           @ApiImplicitParam(name = "icon", value = "icon", dataType = "string", paramType = "query"),
           @ApiImplicitParam(name = "createBy", value = "createBy", dataType = "string", paramType = "query"),
           @ApiImplicitParam(name = "createTime", value = "createTime", dataType = "string", paramType = "query"),
           @ApiImplicitParam(name = "updateBy", value = "updateBy", dataType = "string", paramType = "query"),
           @ApiImplicitParam(name = "updateTime", value = "updateTime", dataType = "string", paramType = "query"),
           @ApiImplicitParam(name = "remark", value = "remark", dataType = "string", paramType = "query"),
        @ApiImplicitParam(name = "pageNo", value = "pageNo", dataType = "int", paramType = "query"),
        @ApiImplicitParam(name = "pageSize", value = "pageSize", dataType = "int", paramType = "query")
    })
    public Result<Page<TMenuDto>> page(
                        @RequestParam(required = false) String menuId,
                        @RequestParam(required = false) String menuName,
                        @RequestParam(required = false) String parentId,
                        @RequestParam(required = false) String orderNum,
                        @RequestParam(required = false) String url,
                        @RequestParam(required = false) String menuType,
                        @RequestParam(required = false) String visible,
                        @RequestParam(required = false) String perms,
                        @RequestParam(required = false) String icon,
                        @RequestParam(required = false) String createBy,
                        @RequestParam(required = false) String createTime,
                        @RequestParam(required = false) String updateBy,
                        @RequestParam(required = false) String updateTime,
                        @RequestParam(required = false) String remark,
                    @RequestParam(required = true) Integer pageNo,
                    @RequestParam(required = true) Integer pageSize) {

        Map<String, String> params = new HashMap<>();
                params.put("menuId",menuId);
                params.put("menuName",menuName);
                params.put("parentId",parentId);
                params.put("orderNum",orderNum);
                params.put("url",url);
                params.put("menuType",menuType);
                params.put("visible",visible);
                params.put("perms",perms);
                params.put("icon",icon);
                params.put("createBy",createBy);
                params.put("createTime",createTime);
                params.put("updateBy",updateBy);
                params.put("updateTime",updateTime);
                params.put("remark",remark);
        return Result.ok(service.page(pageNo, pageSize, params));
    }
}